﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loogn.DataAccess
{
    /// <summary>
    /// 修饰模型类属性
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
    public class DBFieldAttribute : Attribute
    {
        /// <summary>
        /// DBFieldAttribute
        /// </summary>
        public DBFieldAttribute()
            : this(string.Empty)
        {
        }

        /// <summary>
        /// DBFieldAttribute
        /// </summary>
        /// <param name="name"></param>
        public DBFieldAttribute(string name)
        {
            this.Name = name;
        }
        /// <summary>
        /// 指定字段名，推荐属性名和字段名一样，不用指定
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 为Ture时，整体插入时会忽略该字段，如自增
        /// </summary>
        public bool InsertIgnore { get; set; }
        /// <summary>
        /// 为Ture时，整体修改时会忽略该字段，如较大的字段
        /// </summary>
        public bool UpdateIgnore { get; set; }
        /// <summary>
        /// 为Ture时，说明该字段是主键，整体修改时用它作为修改条件
        /// </summary>
        public bool IsPrimaryKey { get; set; }

        /// <summary>
        /// 为Ture时，说明该字段不对应表字段
        /// </summary>
        public bool Ignore { get; set; }
    }

    /// <summary>
    /// 修饰模型类本身
    /// </summary>
    public class DBTableAttribute:Attribute
    {
        /// <summary>
        /// DBTableAttribute
        /// </summary>
        public DBTableAttribute():this(string.Empty) { }

        /// <summary>
        /// DBTableAttribute
        /// </summary>
        /// <param name="name"></param>
        public DBTableAttribute(string name)
        {
            this.Name = name;
        }
        /// <summary>
        /// 指定表名，推荐模型类命名为"表名Info"，不用指定
        /// </summary>
        public string Name { get; set; }
    }
}
